//
//  PIMWPhotoBrowserController.m
//  ClassMatch
//
//  Created by TF_man on 16/8/31.
//  Copyright © 2016年 tituanwang. All rights reserved.
//

#import "PIMWPhotoBrowserController.h"

@interface PIMWPhotoBrowserController ()<MWPhotoBrowserDelegate>



@end

@implementation PIMWPhotoBrowserController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
//    [self creatNavigationCancelButton:^{
//        if (self.succeed) {
//            self.succeed(self.photos);
//        }
//        [self.navigationController popViewControllerAnimated:YES];
//    }];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 30, 22);
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightBtn setTitle:@"删除" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.delegate = self;
    NSLog(@"%@",self.title);
}

- (void)btnClick{
    
//    if (self.navigationItem.title == nil) return;
    NSString *indexStr = [self.title substringToIndex:1];
    NSInteger index = [indexStr integerValue]-1;
    if (index >= 0) {
        [self.photos removeObjectAtIndex:index];
        [self reloadData];
    }if (self.photos.count == 0){
        if (self.succeed) {
            self.succeed(self.photos);
        }
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index {
    NSLog(@"Did start viewing photo at index %lu", (unsigned long)index);
}



@end
